package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;

import javax.swing.JButton;
import javax.swing.JPanel;

import view.interfaces.ViewInterface;

@SuppressWarnings("serial")
public class EcranMenuPrincipal extends JPanel {

	private int w, h;
	private ViewInterface view;

	public EcranMenuPrincipal(int w, int h, ViewInterface view) {

		this.w = w;
		this.h = h;

		this.view = view;

		this.setBackground(Color.BLACK);
		this.setLayout(null);

		JPanel panelMenu = new JPanel();
		panelMenu.setBackground(Color.DARK_GRAY);

		panelMenu.setBounds(w / 4, h / 4, w / 2, h / 2);
		panelMenu.setLayout(null);

		Iterator<String> it = view.getAvailableSimulationsNames().iterator();
		int i = 0;
		while (it.hasNext()) {
			String name = it.next();
			JButton bouton = new JButton(name) {
				public String toString() {
					return getText();
				}
			};
			bouton.setBounds(panelMenu.getWidth() / 4, 15 + i * 30, panelMenu.getWidth() / 2, 30);
			bouton.setBackground(Color.LIGHT_GRAY);
			bouton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent arg0) {
					// System.out.println(arg0.getSource().toString());
					// TODO Passer par enum
					askRunSim(arg0.getSource().toString());
				}
			});
			panelMenu.add(bouton);
			i++;
		}

		this.add(panelMenu, BorderLayout.CENTER);
	}

	protected void askRunSim(String sim) {
		view.askRunSim(sim);

	}

}
